package logic

import (
	"log"
	"mssgserver/constant"
	"mssgserver/db"
	"mssgserver/server/common"
	"mssgserver/server/game/model"
	"mssgserver/server/game/model/data"
)

var DefaultWarService = &WarService{}

type WarService struct {
}

func (w *WarService) Report(rid int) (warReports []model.WarReport, err error) {
	reports := make([]data.WarReport, 0)
	report := &data.WarReport{}
	err = db.Engine.Table(report).Where("a_rid=? or d_rid = ?", rid, rid).Desc("ctime").Limit(30, 0).Find(&reports)
	if err != nil {
		log.Println("查询战报失败", err)
		return nil, common.New(constant.DBError, "查询战报失败")
	}
	modelMrs := make([]model.WarReport, 0)
	for _, warReport := range reports {
		modelMrs = append(modelMrs, warReport.ToModel().(model.WarReport))
	}
	return modelMrs, nil
}
